package com.all.learning.guava.other;

import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.MapMaker;

public class GGcollection {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		

	}

	static void test1() {
		ImmutableList<Integer> list = ImmutableList.of(1, 2, 3);
		System.out.println(list);

		ImmutableSortedSet<String> set = ImmutableSortedSet.of("TSTE", "AAA");
		System.out.println(set);

		ImmutableMap<String, Integer> map = ImmutableMap.of("1", 1, "2", 2, "3", 3);
		System.out.println(map);
	}

	static void test2() {
		ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
		builder.put("name", "value");

		ImmutableMap<String, String> map = builder.build();
		System.out.println(map);
	}

	static void test3() {
		ConcurrentMap<GGcollection, Integer> cache = new MapMaker()//
				.weakKeys().makeMap();

		GGcollection coll = new GGcollection();
		cache.put(coll, 2);
		coll = null;

		System.gc();// 触发垃圾回收
		try {
			TimeUnit.SECONDS.sleep(3L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(cache.isEmpty());
	}
}
